package com.yonyou.sto.modules.ims.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonyou.sto.modules.ims.model.ImsInvoiceItem;
import com.yonyou.sto.modules.ims.model.ImsReturnInvoiceItem;
import com.yonyou.sto.modules.ims.service.ImsInvoiceItemService;
import com.yonyou.sto.modules.ims.service.ImsReturnInvoiceItemService;
import com.yonyou.sto.modules.ims.mapper.ImsReturnInvoiceItemMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
*
*/
@Service
public class ImsReturnInvoiceItemServiceImpl extends ServiceImpl<ImsReturnInvoiceItemMapper, ImsReturnInvoiceItem>
implements ImsReturnInvoiceItemService{

    @Resource
    private ImsInvoiceItemService itemService;

    @Override
    public boolean add(String iid, String rid) {
        //List<ImsInvoiceItem> items = itemService.listByBillIds(Collections.singletonList(iid));
        List<ImsInvoiceItem> items = itemService.list(new LambdaQueryWrapper<ImsInvoiceItem>()
                .in(ImsInvoiceItem::getManualId, Collections.singletonList(iid))
        );
        items.forEach(item->{
            ImsReturnInvoiceItem re = new ImsReturnInvoiceItem();
            BeanUtil.copyProperties(item, re);
            re.setId(null);
            re.setBillId(rid);
            baseMapper.insert(re);
        });
        return true;
    }

    @Override
    public List<ImsReturnInvoiceItem> getListByBillSn(String billSn) {
        return baseMapper.getListByBillSn(billSn);
    }

}
